<template>
	<view class="container">
		<view class="swiper">
			<u-swiper :list="swiperList" height="640rpx" radius="0"></u-swiper>
			<view class="swiper-count">1/5</view>
		</view>
		<view class="goods_box">
			<view class="goods_info">
				<view class="top_price">
					<view class="price_box">
						<view class="present_price">
							<text class="default">￥</text>
							<text>39.8</text>
							<text class="default">/份</text>
						</view>
						<view class="original_price">￥45.8份</view>
					</view>
					<view class="leave_count">
						库存：253件
					</view>
				</view>
				<view class="center_title">
					四川眉山 爱媛38号可吸的果冻橙礼盒装四川眉山果冻橙礼盒装1
				</view>
				<view class="product_box">
					<view class="product_info">
						产地量贩
					</view>
					<view class="product_after">基地优选 售后无忧</view>
				</view>
			</view>

			<view class="wight_serve">
				<view class="weight_box">
					<view class="weight">运费</view>
					<view class="weight_info">24H发货，第三方物流配送，免运费</view>
				</view>
				<view class="weight_box">
					<view class="weight">服务</view>
					<view class="weight_info">品质保证，生鲜不支持7天无理由退货</view>
				</view>
			</view>

			<view class="specifications" @tap="skuPop = true;isPayment = true">
				<view class="specifications_title">选规格</view>
				<u-icon name="arrow-right" color="#666666" size="16"></u-icon>
			</view>

			<view class="user_commment">
				<view class="comment_box">
					<view class="comment_top_box">
						<view class="comment_top">用户评价</view>
						<view class="comment_count">（1685）</view>
					</view>
					<view class="comment_all_box" @tap="goAllComments">
						<view class="comment_all">查看全部</view>
						<u-icon name="arrow-right" color="#666666" size="12"></u-icon>
					</view>
				</view>
				<view class="comment-list">
					<view class="comment-item">
						<view class="left">
							<u-avatar size="60rpx" src="/static/images/avatar.png"></u-avatar>
						</view>
						<view class="right">
							<view class="nickname-box">
								<view class="nickname">金金设计**铺</view>
								<view class="date">2022.10.27</view>
							</view>
							<view class="stars">
								<u-rate inactiveIcon="star-fill" readonly inactiveColor="#DCDEE0" activeColor="#FBA808"
									gutter="6rpx" v-model="star"></u-rate>
							</view>

							<view class="comment-box">
								入手很多，活动力度很大必须囤起来，橙子很好，水分足，甜度可口，没有酸感，大小很合适。
							</view>
							<view class="img-list">
								<view class="img-item" v-for="(key ,index) in 3" :key="index">
									<u-image radius="10rpx" width="110rpx" height="110rpx"
										src="/static/logo.png"></u-image>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 富文本 -->
		<view class="parse-wrap">
			<view class="parse-box">
				<u-parse :content="content"></u-parse>
			</view>
		</view>
		
		<!-- 底部按钮组 -->
		<view class="bottom-btns">
			<uni-goods-nav :fill="true" :options="options" :buttonGroup="buttonGroup" @click="iconClick"
				@buttonClick="buttonClick" />
		</view>
	</view>
	
	<!-- 选择规格弹窗 -->
	<u-popup closeable bgColor="transparent" :show="skuPop" @close="skuPop = false">
		<view class="sku-pop">
			<view class="title">
				选择规格
			</view>
			<view class="content-box">
				<view class="left">
					<u-image width="170rpx" height="155rpx" src="/static/logo.png"></u-image>
				</view>
				<view class="right">
					<view class="com-title">
						<text>￥</text>
						<text class="price">18.32</text>
					</view>
					<view class="sku-box">购买数量：2件</view>
					<view class="count-box">规格：超实惠套装1200g</view>
				</view>
			</view>
			
			<view class="sku-select-box">
				<view class="sku-tip">选择规格</view>
				<view class="sku-list">
					<view :class="['sku-item', skuCurrent == i ? 'active' : '']" v-for="(item, i) in 6" :key="i" @tap="currentChange(i)">尝鲜装150g</view>
				</view>
			</view>
			<view class="sku-select-box pay-number">
				<view class="sku-tip">购买数量</view>
				<view class="sku-num">
					<u-number-box min="1" v-model="num"></u-number-box>
				</view>
			</view>
			<view class="confirm-btn">
				<u-button throttleTime="1000" :customStyle="{height: '80rpx'}" :hairline="false" type="mini" shape="circle" color="linear-gradient(315deg, #4975EC 0%, #97B3FF 100%)" @click="confirmPayment">确认</u-button>
			</view>
		</view>
	</u-popup>

</template>

<script setup>
	// 显示弹窗
	const isPayment = ref(false)
	const skuPop = ref(false)
	const skuCurrent = ref(0)
	const currentChange = (i) => {
		skuCurrent.value = i
	}
	const num = ref(1)
	const star = ref(2)
	// 底部按钮配置
	const options = ref([{
		icon: 'headphones',
		text: '客服'
	}, {
		icon: 'cart',
		text: '购物车',
	}])
	const buttonGroup = ref([{
			text: '加入购物车',
			backgroundColor: '#97B3FF',
			color: '#fff'
		},
		{
			text: '立即购买',
			backgroundColor: '#4975EC',
			color: '#fff'
		}
	])
	const buttonClick = e => {
		// 0 加入购物车 1 立即购买
		console.log(e.index);
		skuPop.value = true
		// 状态是否为立即购买
		isPayment.value = e.index == 1
	}
	const iconClick = e => {
		// 0 客服 1 购物车
		console.log(e.index);
		if (e.index == 0) {
			
		} else if (e.index == 1) {
			uni.navigateTo({
				url: '/mine/drug-store/car'
			})
		}
	}
	// 确认购买/加入购物车
	const confirmPayment = () => {
		if (isPayment.value) {
			uni.navigateTo({
				url: '/mine/drug-store/confirm'
			})
		} else {
			uni.navigateTo({
				url: '/mine/drug-store/car'
			})
		}
	}

	const swiperList = reactive([
		'https://cdn.uviewui.com/uview/swiper/swiper1.png',
		'https://cdn.uviewui.com/uview/swiper/swiper2.png',
		'https://cdn.uviewui.com/uview/swiper/swiper3.png',
	])

	const content = ref('<p>我是富文本</p>')
	
	// 全部评价
	const goAllComments = () => {
		uni.navigateTo({
			url: '/mine/drug-store/comments'
		})
	}
</script>

<style lang="scss" scoped>
	.container {
		padding-bottom: 250rpx;
	}

	.swiper {
		position: relative;

		.swiper-count {
			position: absolute;
			right: 40rpx;
			bottom: 20rpx;
			background: rgba(0, 0, 0, 0.2);
			@include center(80rpx, 40rpx);
			color: #FFFFFF;
			font-size: 24rpx;
			border-radius: 20rpx;
			z-index: 99;
		}
	}

	.goods_box {
		padding: 0 26rpx;
		margin-top: 24rpx;

		.goods_info {
			padding: 24rpx 20rpx;
			background: #FFFFFF;
			border-radius: 20rpx 20rpx 20rpx 20rpx;

			.top_price {
				@include between();

				.price_box {
					display: flex;
					align-items: center;

					.present_price {
						font-size: 44rpx;
						color: #F55726;

						.default {
							font-size: 24rpx;
						}
					}

					.original_price {
						margin-left: 10rpx;
						font-size: 24rpx;
						color: #CCCCCC;
						text-decoration: line-through;
					}
				}

				.leave_count {

					font-size: 24rpx;
					color: #CCCCCC;
				}
			}

			.center_title {

				margin-top: 20rpx;
				font-size: 36rpx;
				color: #333333;
				line-height: 50rpx;
			}

			.product_box {
				display: flex;
				align-items: center;
				margin-top: 20rpx;

				.product_info {
					@include center(106rpx, 39rpx);
					background: #516DDB;
					border-radius: 3rpx;
					font-size: 22rpx;
					color: #FFFFFF;
				}

				.product_after {
					font-size: 22rpx;
					color: #666666;
					margin-left: 16rpx;
				}
			}
		}


		.wight_serve {
			margin-top: 20rpx;
			padding: 30rpx 20rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			@include between(100%, 150rpx);
			flex-direction: column;
			align-items: flex-start;

			.weight_box {
				@include start();

				.weight {
					font-size: 24rpx;
					color: #CCCCCC;
				}

				.weight_info {
					margin-left: 20rpx;
					font-size: 24rpx;
					color: #333333;
				}
			}
		}

		.specifications {
			margin-top: 20rpx;
			padding: 30rpx 20rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			@include between();

			.specifications_title {

				font-size: 24rpx;
				color: #333333;
			}
		}

		.user_commment {
			margin-top: 20rpx;
			padding: 30rpx 20rpx 1rpx;
			background: #FFFFFF;
			border-radius: 20rpx;

			.comment_box {
				@include between(100%);
				border-bottom: 1rpx solid #F2F2F2;
				padding-bottom: 30rpx;
				margin-bottom: 24rpx;

				.comment_top_box {
					@include start();

					.comment_top {

						font-size: 26rpx;
						color: #333333;
					}

					.comment_count {
						font-size: 24rpx;
						color: #CCCCCC;
					}
				}

				.comment_all_box {
					display: flex;
					align-items: center;

					.comment_all {

						font-size: 22rpx;
						color: #666666;
						margin-right: 10rpx;
					}
				}
			}

			.comment-list {
				.comment-item {
					@include between(100%);
					align-items: flex-start;

					.right {
						flex: 1;
						margin-left: 20rpx;

						.nickname-box {
							@include between(100%);

							.nickname {
								color: #333333;
								font-size: 24rpx;
							}

							.date {
								font-size: 22rpx;
								color: #CCCCCC;
							}
						}

						.stars {
							margin-top: 10rpx;
						}

						.comment-box {
							margin-top: 24rpx;
							font-size: 24rpx;
							line-height: 32rpx;
							color: #666666;
							margin-bottom: 28rpx;
						}

						.img-list {
							display: flex;
							align-items: center;
							flex-wrap: wrap;

							.img-item {
								margin-right: 21rpx;
								margin-bottom: 28rpx;
							}
						}
					}
				}
			}
		}
	}

	.parse-wrap {
		margin-top: 20rpx;
		padding: 26rpx;
		background: #FFFFFF;
		width: 100%;
	}
	.sku-pop {
		background: #FFFFFF;
		border-radius: 30rpx 30rpx 0rpx 0rpx;
		padding: 40rpx 40rpx 52rpx;
		.title {
			font-size: 32rpx;
			color: #222222;
			text-align: center;
			margin-bottom: 50rpx;
		}
		.content-box {
			@include between(100%, 100%);
			.right {
				flex: 1;
				margin-left: 22rpx;
				@include between(100%, 170rpx);
				flex-direction: column;
				align-items: flex-start;
				// padding: 10rpx 0;
				color: #000000;
				font-size: 30rpx;
				.com-title {
					color: #F55726;
					font-size: 28rpx;
					.price {
						font-weight: bold;
						font-size: 50rpx;
					}
				}
			}
		}
		.sku-select-box {
			margin-top: 85rpx;
			.sku-tip {
				color: #333333;
				font-size: 30rpx;
				margin-bottom: 30rpx;
			}
			.sku-list {
				@include start();
				flex-wrap: wrap;
				.sku-item {
					padding: 20rpx 26rpx;
					background: #EBEBEB;
					border-radius: 20rpx;
					color: #333333;
					font-size: 30rpx;
					margin-right: 20rpx;
					margin-bottom: 20rpx;
					border: 1rpx solid #EBEBEB;
				}
				.active {
					background: #E8EBF6;
					border: 1rpx solid #516DDB;
				}
			}
		}
		.pay-number {
			margin-top: 50rpx;
			@include between(100%);
		}
		.confirm-btn {
			margin-top: 60rpx;
		}
	}
	
	.bottom-btns {
		width: 100%;
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 999;
		padding-top: 16rpx;
		padding-left: 30rpx;
		padding-right: 30rpx;
		background: #FFFFFF;
		padding-bottom: calc(env(safe-area-inset-bottom) + 16rpx);
		box-shadow: 0rpx 0rpx 16rpx 1rpx rgba(0, 0, 0, 0.1);
	}
</style>